package gui.custom;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;

import javax.swing.ImageIcon;
import javax.swing.JLabel;

public class AALabel extends JLabel
{
	public static final Font LISTFONT = new Font("Verdana", Font.PLAIN, 9);
	
	private int preferredWidth = 150;
	
	public AALabel()
	{
		super();
	}
	
	public AALabel(String str, Font font)
	{
		super(str);
		setFont(font);
	}
	public AALabel(String str)
	{
		this(str, LISTFONT);
	}

	public AALabel(ImageIcon imageIcon)
	{
		super(imageIcon);
	}
	
	public AALabel(String str, final int preferredWidth)
	{
		super(str);
		setFont(LISTFONT);
		this.preferredWidth = preferredWidth;
	}

   @Override
   public Dimension getPreferredSize()
   {
      Dimension superPreferred 	= super.getPreferredSize();
      Dimension dimension 		= new Dimension();
      dimension.setSize(Math.min(preferredWidth,superPreferred.getWidth()),
    		  			superPreferred.getHeight());
      return dimension;
   }
	
	public void paint(Graphics g)
	{
		Graphics2D g2 = (Graphics2D) g;
		g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
		g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT);

		super.paint(g);
	}
}
